thin.define(function(exports) {
	var self = this;

	// 上报
	function main(config, complete) {
		var url = thin.data['data-api'] + '/api?lottm.report&_t=' + Date.now();
		var data_opt = {
			no: thin.data['data-no'],
			mode: thin.store_opts['mode'],
			issue: config.turnNum,
			money: config.totalMoney
		};
		var again = 5;
		request();
	
		function request() {
			thin.ajax.post(url, data_opt, function(res) {
				if (res.state) {
					if (res.data.code == 201 || res.data.code == 404) {
						complete(res.data);
					} else {
						// 上报失败
						if (again > 0) {
							setTimeout(request, 1.6 * 1000);
							--again;
						} else {
							complete();
						}
					}
				} else {
					// 上报失败
					if (again > 0) {
						setTimeout(request, 1.6 * 1000);
						--again;
					} else {
						complete();
					}
				}
			});
		}
	}

	exports('lottmReport', main);
});